<?php
session_start();
if (!isset($_SESSION['login']))
{
        echo "<meta http-equiv='refresh' content='0;url=index.php'>";
}
if(isset($_GET['detail']))
{
	$id = $_REQUEST['detail'];
	
	$connection = mysql_connect('localhost', 'panospet', 'meipei2c');
	if (!$connection) {
	    die('Could not connect: ' . mysql_error());
	}						
	mysql_query("SET NAMES utf8");
	mysql_select_db("panospet");
	
	$query = "SELECT * FROM ukol7_bmi WHERE id = '".$id."' ";
	$result = mysql_query($query);	
	if (!$result) {
	    die('Chyba ve spusteni dotazu: ' . mysql_error());
	}
	else
	{
		$row = mysql_fetch_array($result);
		
		if($row['user_id'] == $_SESSION['id'])
		{		
			$result = mysql_query($query);
			echo "<h2>Detail měření</h2>";
			echo "<table>";
			echo "<tr>";
			echo "<th>Datum</th>";
			echo "<th>Váha</th>";
			echo "<th>Výška</th>";
			echo "<th>BMI</th>";
			
			while ($row = mysql_fetch_array($result)) 
			{
				$zaznam = true;
				echo "<tr>";
				    echo "<td>".$row['date']."</td>";			    
				    echo "<td>".$row['weight']."</td>";
				    echo "<td>".$row['height']."</td>";
				    echo "<td>".$row['bmi']."</td>";
				echo "</tr>";
			}
			echo "</table>";		      
			if(!$zaznam)
			{
				echo "<p>Žádná měření</p>";
			}			
		}
		else
		{
			echo "<p>Pro tuto akci nemáte oprávnění.</p>";	
		}
	}
	
}
else
{
	echo "<meta http-equiv='refresh' content='0;url=index.php'>";	
}

?>
